package com.neu.questionnaire_system.mapper;

import com.neu.questionnaire_system.entity.Choice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neu.questionnaire_system.entity.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xingle
 * @since 2022-11-07
 */
@Mapper
public interface ChoiceMapper extends BaseMapper<Choice> {
    //插入指定问题的选项，需要传入问题id，可选择性传入跳转题目的Id，并多次发送此请求
    @Insert("insert choice values(#{choiceId},#{toQuestion},#{questionId},#{choiceText})")
    int insertChoice(@Param("choiceId")String choiceId,@Param("toQuestion")String toQuestion,
                     @Param("questionId")String questionId,@Param("choiceText")String choiceText);

    //查询某一问题下的全部选项
    @Select("select * from choice where questionId = #{questionId}")
    List<Choice> selectChoiceByQuestionId(@Param("questionId")String questionId);



    //更新指定选项的内容、所属题目的id、跳转题目id
    @Update("update choice set questionId=#{questionId,jdbcType=VARCHAR}," +
            "toQuestion=#{toQuestion,jdbcType=VARCHAR},choiceText=#{choiceText,jdbcType=VARCHAR}" +
            " where choiceId=#{choiceId,jdbcType=VARCHAR}")
    int updateChoice(@Param("questionId")String questionId, @Param("toQuestion")String toQuestion,
                       @Param("choiceText")String choiceText, @Param("choiceId")String choiceId);

    //根据id删除某一选项，没有设置关联删除，所以删除问题的时候要再次请求删除选项，（但是你也可以选择不删除选项，反正也没啥用，只是考虑健壮性）
    @Delete("delete from choice where choiceId=#{choiceId}")
    int deleteChoice(@Param("choiceId")String choiceId);

    //created by libo 删除某一问题的所有选项
    @Delete("delete from choice where questionId=#{questionId}")
    int deleteByQues(@Param("questionId")String questionId);


}
